﻿<!doctype html>
<html><!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>供货商设置</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/formValidator.js"></script>
<script type="text/javascript" src="../js/formValidatorRegex.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/ImageBrowsing.js"></script> 
<script type="text/javascript" src="../js/ajaxfileupload.js"></script> 
<script type="text/javascript" src="../js/city.js"></script>
<script type="text/javascript" src="../js/operateType.js"></script>
<script type="text/javascript" src="../js/industryType.js"></script>
<script type="text/javascript" src="../js/shopType.js"></script>
	<script charset="utf-8" src="../js/kindeditor.js"></script>
	<script charset="utf-8" src="../js/lang/zh_CN.js"></script>
	<link rel="stylesheet" href="../css/default.css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">
#window_change p label span img{
    border: 1px solid #CCCCCC;
    height: 51px;
    vertical-align: middle;
    width: 75px;

}

</style>

<script type="text/javascript" >
function bclicks(obj){
	var $first=obj.parent("td").parent("tr").children("td:first");
	var id=$first.html();
	var name=$first.next().html();
	//$("#shopName").children("option").blur();
	getParamToshopS(id,name)
}
var pagecount = 0;
var count = 0;
var shopId="shopId";
var shopPageCount=0;
var shopCount=0;
var pageIndex=1;
var editor;
var indexStr;
$(function(){
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
		}else{
			$("#shopName").attr("disabled",true);

		}
	})
	getProvince("provinceList");
	getoperateLarge("operateLargeList");
	getIndustry("IndustryList")
	getShopType("shopTypeList");
	addMargin($("#window3"));
	addMargin($("#window4"));
	addMargin($("#window5"));
	addMargin($("#window6"));

	browse('imgURL','imgSrc',75,51)
	browse('imgURL1','imgSrc1',75,51)
	browse('imgURL2','imgSrc2',75,51)
	browse('imgURL3','imgSrc3',75,51)
	browse('imgURL4','imgSrc4',75,51)
	
	$("#editIndex_btn").click( function(){
		var doflag=$("#doflag").val();
		$("#window_changeff,#yinying").show();
		editor= KindEditor.create('#editIndex', {
			pasteType : 2,
			width:670,
			height:400
		});
		editor.html(indexStr);
		addMargin($("#window_changeff"));
	})
	
	var flag=getIdByName('flag');
	if(flag==1){
		InitTable()
	}else if(flag==2){
		var name= getIdByName('name');
		var code=getIdByName('code');
		name= decodeURI(name);
		code=decodeURI(code)
		$("#searchname").val(name);
		$("#searchcode").val(code);
		var p=getIdByName('pageIndex');
		$("#searchstatus").val(getIdByName("searchstatus"))
		pageIndex=p;
		InitTable()
	}
})


function shopExits(id){
	var bloo=false
	$("#shopName").find("option").each(function(){
		
		if($(this).attr("value")===id){
			bloo= true;
			return bloo;
		}
	})
	return bloo;
}


function getParamToshopS(id,name){
	var bl=shopExits(id);
	if(!bl){
		
	var htm="<option value='"+id+"'>"+name+"</option>"
	$("#shopName").html(htm);
	}
	$("#shopName").val(id);
	closeShopShow();
}

function closeShopShow(){
	$("#shopShow,#yinying").hide();
	$("#searchName").val("")
}

function InitShopList(shopPageIndex){
	var shopName=$("#searchName").val();
	$.ajax({
		type : "post",
		async:false,
		data :'name='+shopName,
		datatype : "json",
		url : "../shop/find/shopList/" + shopPageIndex + "/5",
		success : function(data) {
			var rst = JSON.parse(data); 
					 if(IsEmpty(rst)){
							art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
							return false;
							}
							if(rst.state==0){
								$("#shopList tbody tr").remove();

								initShopTable(rst);
								$("table[id='shopList'] tbody tr").each(function(){
									$(this).children("td:last").css("text-align","center").append("<input type='button' class='common_btn' value='选择' onclick='bclicks($(this))'>");

								})	
								if(rst.result.len > 0){
									 var shu = rst.result.len;
									 shopCount = Math.ceil(shu/5);					
									 }else{
											shopCount==0;
									 }
								 $("#shopPager").pager({ pagenumber: ++shopPageIndex, pagecount: shopCount, buttonClickCallback: ShopPageClick });
								 addMargin($("#shopShow"));	
								 }else if(rst.state==1){
								art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
							}else{
								checkStateShowErrorMsgAndDealResult(data);
							}
					
		}	
	});
	
		
	
}

function InitTable() {
	var name=$("#searchname").val().replace(/\s/gi,'');
	var code=$("#searchcode").val().replace(/\s/gi,'');
	var status=$("#searchstatus").val()
	var shopId="";
var param=null;
	if($("#shopIsChoosed").is(":checked")){	
		shopId=$("#shopName").val();
		if(shopId!=""&&shopId!=null){
		//	param+="&shopId="+shopId;
		 param=	{'name':name,'code':code,'status':status,'shopId':shopId}
		}else{
			 param=	{'name':name,'code':code,'status':status}
		}
	}else{
	 param=	{'name':name,'code':code,'status':status}
	}
	
	$.ajax({
		type : "get",
		async:false,
		data :param,
		datatype : "json",
		url : "../supplier/find/supplierList/" + (pageIndex-1) + "/10",
		success : function(data) {
			var dt = JSON.parse(data);						
					 if(IsEmpty(dt)){
							art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
							return false;
							}
							if(dt.state==0){
								$("#memberList tbody tr").remove();
								initTable(dt);
								if(dt.result.len > 0){
									 var shu = dt.result.len;
								 	 pagecount = Math.ceil(shu/10);
									$("#NoResult").hide();
								}else{
									$("#NoResult").show();
									pagecount=0;
								}
								$("#sup").html("共"+dt.result.len+"条");	
								 $("#pager").pager({ pagenumber: pageIndex, pagecount: pagecount, buttonClickCallback: PageClick });
								 }else if(dt.state==1){
								art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
							
								 }else{
								checkStateShowErrorMsgAndDealResult(data);
							}			
					
					
					
		}	
	});
	
		
	
}

ShopPageClick = function(pageclickednumber) {
    $("#shopPager").pager({ pagenumber: --pageclickednumber, pagecount: pagecount, buttonClickCallback: PageClick });
    $("#result").html("Clicked Page " + pageclickednumber);
    InitShopList(pageclickednumber);
}

PageClick = function(pageclickednumber) {
	pageIndex=pageclickednumber;
	InitTable();
}

function search(){
	pageIndex=1;
	InitTable();
}
function search2(){
	InitShopList(0);
}
function initTable(json){
	if(json!=null && json.state==0){
		var params = new Array( "code","name", "tel", "fax","email", "createFileTime", "staName");// "PayCash", "PayPos", "PayDepstAmt", "PayCheck", "PayPersonCard", "PayIntAmtMny", "StaName", "PaidName"
		Loadtable(json,params,"memberList");
	}
}



function initShopTable(json){
	if(json!=null && json.state==0){
		var params = new Array("id", "name","mp","contact");
		LoadShoptable(json,params,"shopList");
	}
}


function Loadtable(json, params, tableId){
	var phArray = new Array();
	var count = 0;
	if (params != null) {
		$(params).each(function(pIndex, pData) {
			$.each(json.result.head, function(hIndex, hData) {
				
				if (pData == hData) {
					phArray[count++] = hIndex;
				}
			});
		});
	}
	if (json.result.data != null) {
		$.each(json.result.data, function(index, dt) {
			$("table[id='" + tableId + "']").append("<tr></tr>");
			$(phArray).each(function(phIndex, data) {
				$.each($(dt), function(dtIndex, d) {
					if (dtIndex == data) {
						
						$("table[id='" + tableId + "'] tr:last").append("<td>" +  (d === null||d=="null" ? " " : d) + "</td>");
					}
				});
			});
		
		var id=getHeadIndexValue(index, json, "id")
		var htm="<td><input class='common_btn' type='button' onclick='toUpdate("+id+")' value='修改'><br> <input class='del common_btn' type='button' onclick='popPoint("+id+")' value='删除'>  </td>"
		$("table[id='" + tableId + "'] tbody tr:last").append(htm)
		});
		
	}
	
}
function LoadShoptable(json, params, tableId){
	var phArray = new Array();
	var count = 0;
	if (params != null) {
		$(params).each(function(pIndex, pData) {
			$.each(json.result.head, function(hIndex, hData) {
				
				if (pData == hData) {
					phArray[count++] = hIndex;
				}
			});
		});
	}
	if (json.result.data != null) {
		$.each(json.result.data, function(index, dt) {
			$("table[id='" + tableId + "']").append("<tr></tr>");
			$(phArray).each(function(phIndex, data) {
				$.each($(dt), function(dtIndex, d) {
					if (dtIndex == data) {                 
						$("table[id='" + tableId + "'] tr:last").append("<td>" +  (d === null||d=="null" ? " " : d) + "</td>");
					}
				});
			});
		});
		
	}
	


	
}

function showShopList(){
	$("#shopIsChoosed").attr("checked","checked");
	$("#shopName").blur();
	$("#shopShow,#yinying").show();
	InitShopList(0);
}


function  downRescouse(){
	var name=$("#name").val().replace(/\s/gi,'');
	var code=$("#code").val().replace(/\s/gi,'');
	var status=$("#status").val()
	var shopId="";
	var param="name="+name+"&code="+code+"&status="+status;
	if($("#shopIsChoosed").is(":checked")){

		
		shopId=$("#shopName").val();
		
		if(shopId!=""&&shopId!=null){
			param+="&shopId="+shopId;
		}
	}
	
		param+="&downType=6"
		
		window.location.href="../csvdown/down/csv/down?"+param

	}
	
function toAdd(){
	
	window.location.href="addSupplier.html"

}
function toUpdate(id){
	window.location.href="makeSupplier.html?id="+id+"&name="+$("#searchname").val()+"&code="+$("#searchcode").val()+"&pageIndex="+pageIndex+"&searchstatus="+$("#searchstatus").val();
	
}

function deleteInfo(id){
	
		$.post("../supplier/del/deleteInfo",{"id":id}, function(data) {
			var dt = JSON.parse(data);
			if(IsEmpty(dt)){
				art.dialog({fixed:true, lock: true,content:"删除出错",icon:'error',ok:true});	
				return false;
				}
				if(dt.state==0){
					InitTable();
					art.dialog({fixed:true, lock: true,content:"删除成功",icon:'succeed',ok:true});	
				}else if(dt.state==1){
					art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
		});
	
}

	
function popPoint(id){
	art.dialog({fixed:true, lock: true,content:"确认删除该条数据？",icon:'question',ok: function(){ deleteInfo(id)},cancel:true});
	}

	
</script>
</head>

<body>
<div id="yinying1"></div>
<div id="yinying"></div>
<div id="window_changeff" class="hideDiv"  style=" width:650px;background:#fff;z-index:400;"  >
	<textarea id="editIndex" name="editIndex"></textarea>
	<div class="BottomBtn">
        <input type="button"  value="确定" class="common_btn" onclick="saveHtml()" >
        <input type="button" value="取消" class="common_btn" style="background-color: red;" onclick="cancelHtml()" >
      </div>
</div>
<div id="shopShow" class="hideDiv">
    <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="closeShopShow();" >X</span> </div>
    <div class="bottom_search"><input type="text" id="searchName"><input type="button" style="width:auto;margin-left:5px;" value="查询" onclick="search2()"></div>
    <table   id="shopList" cellpadding="4" cellspacing="0" border="1" width="100%">
    <thead>
    <tr>
    <th>店面ID</th>
    <th>店面名称</th>
    <th>电话</th>
    <th>操作</th>
    </tr>
    </thead>
    </table>
    	<div id="shopPager"></div>
    </div>
<!-- InstanceBeginEditable name="EditRegion3" -->
<script type="text/javascript" src="../js/jquery.cityselect.js"></script>
<script type="text/javascript">
$(function(){
	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	
});
</script>
<form id="valiForm" >
  <div id="window_change" class="member_search hideDiv" style="width:800px;">
    <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
    <input type="hidden" id="doflag">
    <input type="hidden" id="shopflag">
    <input type="hidden" id="defaultCflag">
    <input type="hidden" id="updateId">
	<p style="white-space: nowrap;">
      <label><span>编码：</span>
        <input type="text" id="code">
      </label>
      <label><span>全称：</span>
        <input type="text" id="name">
      </label>
      <label><span>简称：</span>
        <input type="text" id="sName">
      </label>
    </p>
    <p>
      <label><span>传真：</span>
        <input type="text" id="fax">
      </label>
      <label><span>电话：</span>
        <input type="text" id="tel">
      </label>
      <label><span>邮箱：</span>
        <input type="text" id="email"></span>
      </label>
    </p>
    <p id="city_1">
		<label><span>省（市）：</span>
	<input type="text" onclick="showHideDiv('window1');" id="provinceName" readonly >
	</label>
		<label><span>城市（区）：</span>
		<input type="text" onclick="showCityList(); " id="cityName" readonly></label>
      <label><span>会员卡标识：</span>
        <input type="text" id="cardFlag" />
        </label>
	</p>
    <p>
      <label><span>工商注册号：</span>
        <input type="text" id="regNo">
      </label>
      <label><span>法定代表人：</span>
        <input type="text" id="legal">
      </label>
      <label><span>状态：</span>
        <select id="status"><option value="0">正常</option><option value="1">非正常</option></select>
      </label>
    </p>
    <p>
		<label><span>经营大类：</span>
		<input type="text" onclick="showHideDiv('window5');" id="operateLargeTypeName" readonly></label>
		<label><span>经营小类：</span>
		<input type="text" onclick="showOperateType();"  id="operateTypeName" readonly></label>
      <label><span>行业类型：</span>
        <input type="text" id="industryName" readonly onclick="showHideDiv('window3');">
      </label>
	</p>
    <p>
		<label><span>地址：</span>
        <input type="text" id="addr">
      </label>
      <label style="min-width:0;"><input type="button" value="获取坐标" class="btn" onclick="findXY()"></label>
      <label style="min-width:0;"><span style="min-width:0;">X:</span><input type="text" style="width:52px;" id="lat" readonly></label>
      <label style="min-width:0;"><span style="min-width:0;">Y:</span><input type="text" style="width:52px;" id="lng" readonly></label>
      <label><span>店面类型：</span>
        <input type="text" id="shopTypeName" readonly onclick="showHideDiv('window4');">
      </label>
    </p>
    <p>
		<label><span>店面首页：</span>
		<input type="text" id="indexUrl" readonly style="width:300px;"></label>
        <input type="button" value="编辑首页" class="btn" id="editIndex_btn" />
	</p>
    <p>
      <label><span>品牌图：</span>
        <span id="imgSrc" style="width:77px;height:53px;"><img src="../images/logo.png" class="popImg"  style="width: 75px;height: 51px"  ></span>
        <input type="button" value="选择" class="btn">
        <input type="file" class="file" id="imgURL" name="imgURL" >
      </label>
      <label><span>店面图一：</span>
        <span id="imgSrc1" style="width:77px;height:53px;"><img src="../images/logo.png" class="popImg"   style="width: 75px;height: 51px" /></span>
        <input type="button" value="选择" class="btn">
        <input type="file" class="file" id="imgURL1" name="imgURL1" >
      </label>
      <label><span>店面图二：</span>
        <span id="imgSrc2" style="width:77px;height:53px;"><img src="../images/logo.png" class="popImg"   style="width: 75px;height: 51px" /></span>
        <input type="button" value="选择" class="btn">
        <input type="file" class="file" id="imgURL2" name="imgURL2" >
      </label>
    </p>
    <p>
       <label><span>店面图三：</span>
        <span id="imgSrc3" style="width:77px;height:53px;"><img src="../images/logo.png" class="popImg"   style="width: 75px;height: 51px" /></span>
        <input type="button" value="选择" class="btn">
        <input type="file" class="file" id="imgURL3" name="imgURL3" >
      </label>
      <label><span>店面图四：</span>
        <span id="imgSrc4" style="width:77px;height:53px;"><img src="../images/logo.png" class="popImg"   style="width: 75px;height: 51px" /></span>
        <input type="button" value="选择" class="btn">
        <input type="file" class="file" id="imgURL4" name="imgURL4" >
      </label>
    </p>
    <p>
      <label><span>简介：</span>
        <textarea id="memo"></textarea>
      </label>
      <label><span>经营范围：</span>
        <textarea id="major"></textarea>
      </label>
    </p>
    
    <div class="submit_btn">
      <input type="button" value="保存信息"  onclick="save();" class="common_btn" id="close_this">
    </div>
  </div>
</form>
<!-- 省（市）-->
<div class="hideDiv hideOver" id="window1">
 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
	<table id="provinceList" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
    	<thead>
    	<tr>
        	<th>省份</th>
        	<th>操作</th>
        	<th>省份</th>
        	<th>操作</th>
        	<th>省份</th>
        	<th>操作</th>
        	<th>省份</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
    </table>
</div>
<!-- 城市（区）-->
<div class="hideDiv hideOver" id="window2">
 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
	<table id="cityList" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
    	<caption>经营小类    </caption>
    	<thead>
    	<tr>
        	<th>城市</th>
        	<th>操作</th>
        	<th>城市</th>
        	<th>操作</th>
        	<th>城市</th>
        	<th>操作</th>
        	<th>城市</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
    </table>
</div>
<!-- 行业类型 -->
<div class="hideDiv hideOver" id="window3">
 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
	<table id="IndustryList" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
    	<caption>行业类型       </caption>
    	<thead>
    	<tr>
        	<th>行业类型</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
    </table>
    <div id="indusPager" class="shopPager"></div>
</div>
<!-- 店面类型 -->
<div class="hideDiv hideOver" id="window4">
 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
	<table id="shopTypeList" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
    	<caption>店面类型      </caption>
    	<thead>
    	<tr>
        	<th>店面类型</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        
        </tbody>
    </table>
</div>
<!-- 经营大类 -->
<div class="hideDiv hideOver" id="window5">
 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
	<table id="operateLargeList" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
    	<caption>经营大类       </caption>
    	<thead>
    	<tr>
        	<th>类别</th>
        	<th>操作</th>
        	<th>类别</th>
        	<th>操作</th>
        	<th>类别</th>
        	<th>操作</th>
        	<th>类别</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
    </table>
</div>
<!-- 经营小类 -->
<div class="hideDiv hideOver" id="window6">
 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
	<table id="operateTypeList" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
    	<caption>经营小类         </caption>
    	<thead>
    	<tr>
        	<th>类别</th>
        	<th>操作</th>
        	<th>类别</th>
        	<th>操作</th>
        	<th>类别</th>
        	<th>操作</th>
        	<th>类别</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
    </table>
</div>
<div class="container" id="container">
  <div class="container_R fr">
	<div class="place">供货商设置</div>
    <div class="member_search">

    <p>
    <span>供货商名称：</span><input type="text" id="searchname" class="absoluteTxt"><span>供货商编码：</span><input type="text" id="searchcode" class="absoluteTxt"><span>状态：</span><select id="searchstatus" class="status"> <option value="">所有</option>  <option value="1">正常</option><option value="0">非正常</option></select><input type="button" value="查询" class="btn" onclick="search()"></p></div>
    
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
    	<caption><strong>供货商列表        <span id="sup">共0条</span> </strong> <!--  <a href="javascript:void(0)" onclick="downRescouse();">导出数据</a> --> <input type="button" value="添加供应商" onclick="toAdd()" class="common_btn addList"></caption>
    	<thead>
    	<tr>
        	<th >编码</th>
        	<th >名称</th>
        	<th >电话</th>
        	<th>传真</th>
        	<th >邮箱</th>
        	<th >加入时间</th>
        	<th >状态</th>
        	<th >操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
    </table>
    <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager" style="float: right;"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/header.js"></script>
<script type="text/javascript" src="../js/left.js"></script>
<script type="text/javascript" src="../js/footer.js"></script>
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(2,5);
</script>
</body>
<!-- InstanceEnd --></html>
